package com.google.code.example;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;

public class AppConfig {
	
	public static List<String> PROXIES;
	
	public static int API_ACCESS_LIMIT_PER_DAY = 100;
	
	public static int TIME_PAUSE = 70000;
	
	public static String INPUT_FILE = "";
	
	public static String OUTPUT_FILE = "";
	
	public static void initConfig(Properties properties) {
		API_ACCESS_LIMIT_PER_DAY = Integer.parseInt(properties.getProperty("batchOfRequests"));
		TIME_PAUSE = Integer.parseInt(properties.getProperty("timePause"));
		INPUT_FILE = properties.getProperty("inputFile");
		OUTPUT_FILE = properties.getProperty("outputFile");
		PROXIES = fromStrToList(properties.getProperty("proxies"), ",");
	}
	
	public static List<String> fromStrToList(String source, String delimiter) {
        List<String> list = new ArrayList<String>();
        if (source != null && !source.equals("")) {
            StringTokenizer tokenizer = new StringTokenizer(source, delimiter);
            while (tokenizer.hasMoreTokens()) {
                list.add(tokenizer.nextToken());
            }
        }
        return list;
    }
}
